package com.company.zoj;

import java.util.Scanner;

/**
 * Created by v on 17-6-4.
 */
public class ZojTest1002 {
    static int max;
    static char[][] map;
    static int n;

    //判断上是否可以放炮
    static boolean canPut(int current){
        int row=current/n;
        int column=current%n;

        //往左一次
        for(int i=row,j=column;i>=0;i--){
            if(map[i][j]=='O'){
                return false;
            }else if(map[i][j]=='X'){
                break;
            }
        }

        for(int i=row,j=column;j>=0;j--){
            if(map[i][j]=='O'){
                return false;
            }else if(map[i][j]=='X'){
                break;
            }
        }

        return true;
    }

    //深搜
    static void dfs(int current,int number){
        int row=current/n;
        int column=current%n;
        if(current==n*n){
            if(max<number){
                max=number;
            }
            return;
        }

        //为空，且能放置
        if(map[row][column]=='.'&&canPut(current)){
            map[row][column]='O';
            dfs(current+1,number+1);
            map[row][column]='.';
        }

        dfs(current+1,number);
    }

    public static void main(String[] args) {
        try {
            Scanner input=new Scanner(System.in);
            while (true){
                n=input.nextInt();
                if(n==0){
                    return;
                }

                max=0;
                map=new char[n][n];
                for(int i=0;i<n;i++){
                    String line=input.next();
                    for(int j=0;j<n;j++){
                        map[i][j]=line.charAt(j);
                    }
                }
                dfs(0,0);
                System.out.println(max);
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
